package org.jackysoft.workflow.util;

import java.util.Map;

import org.jackysoft.entity.OsVariable;
import org.jackysoft.entity.WorkflowRunner;
import org.jackysoft.service.OsVariableService;
import org.jackysoft.service.OsWorkflowRunnerService;
import org.jackysoft.workflow.Condition;
import org.jackysoft.workflow.WorkflowException;

/**
 * <DD>这个类主要用来检查会签到达后是否同签的要求 <DD>
 * 
 * &lt;condition type="class"&gt;<br>
 * &lt;arg name="class.name"&gt;
 * com.opensymphony.workflow.util.TeamJoinCondition &lt;/arg&gt;<br/>
 * &lt;/condition&gt;
 * 
 * <DD>
 * 
 * */
public class TeamJoinCondition implements Condition {
	String status = "Finished";

	@Override
	public boolean passesCondition(Map transientVars, Map args,
			OsVariableService vservice) throws WorkflowException {
		// TODO 从持久化变量里找到 会签所需要汇聚的步骤

		WorkflowRunner entry = (WorkflowRunner) transientVars.get("entry");
		String teamstep = null;
		OsVariable wv = vservice.findOneByName(entry.getId(), "teamstep");
		if (wv == null)
			throw new WorkflowException("会签步骤异常,请检查会签节点");
		teamstep = wv.getValue();
		String[] steps = teamstep.split("\\,");
		OsWorkflowRunnerService store = (OsWorkflowRunnerService) transientVars.get("store");
		for (String s : steps) {
			Integer sid = Integer.parseInt(s);
			if (!store.stepIsStatus(sid, status))
				return false;
		}
		return true;
	}

}
